package com.example.photography.adapter.home_recommed;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.Home_RecommendBean;
import com.example.photography.bean.UrlBean;
import com.example.photography.util.Util;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public abstract class Hot_ProductAdapter extends MyBaseAdapter {
    public Hot_ProductAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_hotproduct, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Home_RecommendBean.HotProductBean  hotProductBean= (Home_RecommendBean.HotProductBean) list.get(position);
        viewHolder.tvNum.setText("NO."+(position+1)+"");
        viewHolder.tvName.setText(hotProductBean.getName());
        viewHolder.svHead.setImageURI(hotProductBean.getHead_url());
        List<UrlBean> urlBeans = JSONObject.parseArray(hotProductBean.getProduct(), UrlBean.class);
        viewHolder.svProduct.setImageURI(urlBeans.get(0).getUrl());
        viewHolder.llItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toproduct_detail(hotProductBean.getProduct_id());
            }
        });
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.sv_product)
        SimpleDraweeView svProduct;
        @BindView(R.id.tv_num)
        TextView tvNum;
        @BindView(R.id.sv_head)
        SimpleDraweeView svHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.ll_item)
        LinearLayout llItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
    abstract void toproduct_detail(String product_id);
}
